<?php

use com\gdl\newagk\interfaces\BasicuserServiceIf;
use com\gdl\common\dataobject\common\ResultDO;
use com\gdl\newagk\dataobject\basicuser\BasicuserDTO;
use com\gdl\newagk\dataobject\basicuser\BasicuserRequestDTO;


class api_BasicuserService extends api_Abstract implements BasicuserServiceIf
{

	//参考人员列表
	public function basicUserList(BasicuserRequestDTO $basic)
    {
		$result = new ResultDO();
		$datas = $basic->filename ? $basic->filename : [];
		$page = ($datas['page']-1) * $datas['pagesize'];

		$down = $basic->filename['down'] ? $basic->filename['down'] : '';
		$downid = $basic->filename['id'] ?  explode(',',$basic->filename['id']) : '';

		
		try{
			$basicuser = new model_newagk_basicuser();
			$usercompany = new model_newagk_usercompany();
			$ucentermember = new model_agkuc_ucentermember();
			$member = new model_agkuc_member();

			$users = new model_newagk_user();
			$condition = $basicuser->tableName().'.basic_id='.$datas['basicid'];
			if(!empty($datas['title'])){
				$condition .= ' and ('.$basicuser->tableName().'.id='.intval($datas['title'])." or c.realName like '%{$datas['title']}%' or c.mobile like '%{$datas['title']}%' or c.idcard like '%{$datas['title']}%' )";
			}
			if($datas['sex']=='boys'){
				$condition .= ' and c.sex=0';
			} else if($datas['sex']=='girls'){
				$condition .= ' and c.sex=1';
			}
			$dataY = date('Y');
			switch($datas['age'])
			{
				case '19':
					$ages = $dataY-19;
//					$condition .= ' and substring(d.idcard, 7, 8)<'.$ages;
                    $condition .= ' and (YEAR (NOW()) - substring(c.idcard, 7, 4))<19';
				break;
				case '20~29':
					$ages = $dataY-20;
					$age2 = $dataY-29;
//                        $condition .= ' and substring(d.idcard, 7, 4)<'.$ages.' and substring(d.idcard, 7, 8)>'.$age2;
                    $condition .= ' and (YEAR (NOW()) - substring(c.idcard, 7, 4))>=20  and (YEAR (NOW()) - substring(c.idcard, 7, 4))<=29 ';
				break;
				case '30~39':
					$ages = $dataY-30;
					$age2 = $dataY-39;
//					$condition .= ' and substring(d.idcard, 7, 8)<'.$ages.' and substring(d.idcard, 7, 8)>'.$age2;
                    $condition .= ' and (YEAR (NOW()) - substring(c.idcard, 7, 4))>=30  and (YEAR (NOW()) - substring(c.idcard, 7, 4))<=39 ';
				break;
				case '40~49':
					$ages = $dataY-40;
					$age2 = $dataY-49;
//					$condition .= ' and substring(d.idcard, 7, 8)<'.$ages.' and substring(d.idcard, 7, 8)>'.$age2;
                    $condition .= ' and (YEAR (NOW()) - substring(c.idcard, 7, 4))>=40  and (YEAR (NOW()) - substring(c.idcard, 7, 4))<=49 ';
				break;
				case '50':
					$ages = $dataY-50;
//					$condition .= ' and substring(d.idcard, 7, 8)<'.$ages;
                    $condition .= ' and (YEAR (NOW()) - substring(c.idcard, 7, 4))>50  ';
				break;
			}
			if($datas['companyId']){
				$condition .= ' and b.companyId='.$datas['companyId'];
			}

			if($datas['departmentId']){
				$condition .= ' and b.departmentId='.$datas['departmentId'];
			}
			if($datas['departmentgroupId']){
				$condition .= ' and b.departmentgroupId='.$datas['departmentgroupId'];
			}
			if($datas['groupId']){
				$condition .= ' and b.groupId='.$datas['groupId'];
			}
			if($datas['specialtyId']){
				$condition .= ' and b.specialtyId='.$datas['specialtyId'];
			}
			
			if($datas['vface']!=99){
				$condition .= ' and b.vface='.$datas['vface'];
			}
			
			
			$leftJoin = array(
				$usercompany->tableName().' as b' => $basicuser->tableName().'.identity_id=b.id',
				$users->tableName().' as c' =>  'b.userId=c.userId',
			);
			if($down=='excels'){
				$orderBy = ' order by '.$basicuser->tableName().'.id desc';
			} else {
				$orderBy = ' order by '.$basicuser->tableName().'.id desc  limit '.$page.','.$datas['pagesize'];
			}
			
			
			if($down=='excels' && !empty($downid) ){
				$dow_id = [0];
				foreach($downid as $v){
					$dow_id[] = intval($v);
				}
				$condition = $basicuser->tableName().'.id in('.implode(',',$dow_id).')';
			}
			
			/******查询条件********/
			/******查询条件 end********/
			$items = $basicuser->tableName().'.id,b.companyName,b.companyId,b.vface,b.departmentId,b.id as identity_id,b.departmentgroupId,b.groupId,b.specialtyId,b.photoCollect,c.sex,b.gdlUserId,c.realName,c.mobile,c.idcard,b.position,c.age';
			$num = $basicuser->selectOne($condition, 'count('.$basicuser->tableName().'.id) num','', '', $leftJoin);
			$res = $basicuser->select($condition, $items, $orderBy, '', $leftJoin)->items;
			$datas = [];
			
			$UserSpecialty = new model_newagk_specialty(); //实例化专业
			$Specialty = $UserSpecialty->getList(1);
			$Specialty = self::setArrKeyId($Specialty);

			$Department = new model_newagk_department();//实例化 部门
			$depart = $Department->getList(1);
			$depart = self::setArrKeyId($depart);
			
				
			$Company = new model_newagk_company();//实例化公司
			$CompanyName = $Company->getList(1);
			$CompanyName = self::setArrKeyId($CompanyName);


            $result->success = true;
			$team = [];
			foreach($depart as $vc){
				if($v['pid']>0){
					$team[$v['id']] = $v['name'];
				}
			}
			$positions = ['1'=>['id'=>1,'name'=>'安置','pid'=>0],'2'=>['id'=>1,'name'=>'检修','pid'=>0],'3'=>['id'=>1,'name'=>'送变电','pid'=>0]];//职位
			$vfaceArr = ['未审核','审核失败','审核通过','审核中'];
			if($down=='excels'){

				foreach($res as $v){
				$vface = empty($v['photoCollect']) ? '未上传照片' : $vfaceArr[$v['vface']];

				$Borns = empty($v['idcard']) ? '' : $dataY-substr($v['idcard'],6,4);
				$datas[] = [
						'id'=>$v['id'],
						'truename'=>$v['realName'], //姓名
						'idcard'=>'|'.$v['idcard'],	//身份号
						'phone'=>$v['mobile'],	//手机号
						'sex'=>$v['sex']==1 ? '女' : '男',		//性别
						'ages'=>intval($v['age']),		//年龄
						'company_name'=>empty($CompanyName[$v['companyId']]["name"]) ? $v['companyName'] : $CompanyName[$v['companyId']]["name"], //公司
						'departmentId'=>empty($depart[$v['departmentId']]["name"]) ? '' : $depart[$v['departmentId']]["name"], //部门
						'teams'=>empty($depart[$v['departmentgroupId']]["name"]) ? '' : $depart[$v['departmentgroupId']]["name"], //班组
						'position'=>empty($Specialty[$v['position']]["name"]) ? '' : $Specialty[$v['position']]["name"], //职位
						'specialtyId'=>empty($Specialty[$v['specialtyId']]["name"]) ? '' : $Specialty[$v['specialtyId']]["name"], //专业
						'vface'=>$vface,
							];
				}
			
			} else {
				
				foreach($res as $v){

				//$uid[] = $v['uid'];
				$Borns = empty($v['idcard']) ? '' : $dataY-substr($v['idcard'],6,4);//intval
				$datas[] = [
						'id'=>$v['id'],
						'basicid'=>$basic->filename['basicid'],
						'userid'=>$v['identity_id'],
						'uid'=>$v['gdlUserId'],
						'truename'=>$v['realName'], //姓名
						'idcard'=>$v['idcard'],	//身份号
						'phone'=>$v['mobile'],	//手机号
						'sex'=>$v['sex']==1 ? '女' : '男',		//性别
						'ages'=>intval($v['age']),		//年龄
						'company_name'=>empty($CompanyName[$v['companyId']]["name"]) ? $v['companyName'] : $CompanyName[$v['companyId']]["name"], //公司
						'departmentId'=>empty($depart[$v['departmentId']]["name"]) ? '' : $depart[$v['departmentId']]["name"], //部门
						'teams'=>empty($depart[$v['departmentgroupId']]["name"]) ? '' : $depart[$v['departmentgroupId']]["name"], //班组
						'position'=>empty($Specialty[$v['position']]["name"]) ? '' : $Specialty[$v['position']]["name"], //职位
						'specialtyId'=>empty($Specialty[$v['specialtyId']]["name"]) ? '' : $Specialty[$v['specialtyId']]["name"], //专业
						'vface'=>$v['vface'],
						'photo'=>empty($v['photoCollect']) ? 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1295886065,1357964878&fm=27&gp=0.jpg' : $v['photoCollect'], //留底
							];
				}
				
			}

			if(empty($datas)){
				$result->code = 0;
			} else {
				$datac['Specialty'] = is_array($Specialty) ? $Specialty : [];
				$datac['depart'] = is_array($depart) ? $depart : [];
				$datac['company'] = is_array($Company) ? $Company : [];
				$datac['team'] = is_array($team) ? $team : [];
				$datac['positions'] = is_array($positions) ? $positions : [];
				$datac['num'] = $num['num'];
				$result->code = 1;
				$result->data = $datas;
				$result->message = json_encode($datac);
			}

            $result->success = true;
		} catch (Exception $e) {
            $result->success = false;
            $result->code = $e->getCode();
            $result->message = $e->getMessage();
        }
        return $result;
	}
	
  /*  public function basicUserList(BasicuserRequestDTO $basic)
    {
		$result = new ResultDO();
		$datas = $basic->filename ? $basic->filename : [];
		$page = ($datas['page']-1) * $datas['pagesize'];

		$down = $basic->filename['down'] ? $basic->filename['down'] : '';
		$downid = $basic->filename['id'] ?  explode(',',$basic->filename['id']) : '';

		
		try{
			$basicuser = new model_newagk_basicuser();
			$usercompany = new model_newagk_usercompany();
			$ucentermember = new model_agkuc_ucentermember();
			$member = new model_agkuc_member();
			$condition = $basicuser->tableName().'.basic_id='.$datas['basicid'];
			if(!empty($datas['title'])){
				$condition .= ' and ('.$basicuser->tableName().'.id='.intval($datas['title'])." or d.truename like '%{$datas['title']}%' or d.mobile like '%{$datas['title']}%' or d.idcard like '%{$datas['title']}%' )";
			}
			if($datas['sex']=='boys'){
				$condition .= ' and c.sex=1';
			} else if($datas['sex']=='girls'){
				$condition .= ' and c.sex=0';
			}
			$dataY = date('Y');
			switch($datas['age'])
			{
				case '19':
					$ages = $dataY-19;
//					$condition .= ' and substring(d.idcard, 7, 8)<'.$ages;
                    $condition .= ' and (YEAR (NOW()) - substring(d.idcard, 7, 4))<19';
				break;
				case '20~29':
					$ages = $dataY-20;
					$age2 = $dataY-29;
//                        $condition .= ' and substring(d.idcard, 7, 4)<'.$ages.' and substring(d.idcard, 7, 8)>'.$age2;
                    $condition .= ' and (YEAR (NOW()) - substring(d.idcard, 7, 4))>=20  and (YEAR (NOW()) - substring(d.idcard, 7, 4))<=29 ';
				break;
				case '30~39':
					$ages = $dataY-30;
					$age2 = $dataY-39;
//					$condition .= ' and substring(d.idcard, 7, 8)<'.$ages.' and substring(d.idcard, 7, 8)>'.$age2;
                    $condition .= ' and (YEAR (NOW()) - substring(d.idcard, 7, 4))>=30  and (YEAR (NOW()) - substring(d.idcard, 7, 4))<=39 ';
				break;
				case '40~49':
					$ages = $dataY-40;
					$age2 = $dataY-49;
//					$condition .= ' and substring(d.idcard, 7, 8)<'.$ages.' and substring(d.idcard, 7, 8)>'.$age2;
                    $condition .= ' and (YEAR (NOW()) - substring(d.idcard, 7, 4))>=40  and (YEAR (NOW()) - substring(d.idcard, 7, 4))<=49 ';
				break;
				case '50':
					$ages = $dataY-50;
//					$condition .= ' and substring(d.idcard, 7, 8)<'.$ages;
                    $condition .= ' and (YEAR (NOW()) - substring(d.idcard, 7, 4))>50  ';
				break;
			}
			if($datas['companyId']){
				$condition .= ' and b.companyId='.$datas['companyId'];
			}

			if($datas['departmentId']){
				$condition .= ' and b.departmentId='.$datas['departmentId'];
			}
			if($datas['departmentgroupId']){
				$condition .= ' and b.departmentgroupId='.$datas['departmentgroupId'];
			}
			if($datas['groupId']){
				$condition .= ' and b.groupId='.$datas['groupId'];
			}
			if($datas['specialtyId']){
				$condition .= ' and b.specialtyId='.$datas['specialtyId'];
			}
			
			if($datas['vface']!=99){
				$condition .= ' and b.vface='.$datas['vface'];
			}
			
			
			$leftJoin = array(
				$usercompany->tableName().' as b' => $basicuser->tableName().'.identity_id=b.id',
				'uc.'.$member->tableName().' as c' => 'b.gdlUserId=c.uid',
				'uc.'.$ucentermember->tableName().' as d' => 'c.uid=d.id'
			);
			if($down=='excels'){
				$orderBy = ' order by '.$basicuser->tableName().'.id desc';
			} else {
				$orderBy = ' order by '.$basicuser->tableName().'.id desc  limit '.$page.','.$datas['pagesize'];
			}
			
			
			if($down=='excels' && !empty($downid) ){
				$dow_id = [0];
				foreach($downid as $v){
					$dow_id[] = intval($v);
				}
				$condition = $basicuser->tableName().'.id in('.implode(',',$dow_id).')';
			}*/
			
			/******查询条件********/
			/******查询条件 end********/
			/*$items = $basicuser->tableName().'.id,b.companyName,b.departmentId,b.id as identity_id,b.departmentgroupId,b.groupId,b.specialtyId,b.photoCollect,c.uid,c.sex,b.gdlUserId,d.truename,d.mobile,d.idcard';
			$num = $basicuser->selectOne($condition, 'count(*) num');
			$res = $basicuser->select($condition, $items, $orderBy, '', $leftJoin)->items;
			$datas = [];
			
			$UserSpecialty = new model_newagk_specialty(); //实例化专业
			$Specialty = $UserSpecialty->getList(1);
			$Specialty = self::setArrKeyId($Specialty);
			$Department = new model_newagk_department();//实例化 部门
			$depart = $Department->getList(1);
			$depart = self::setArrKeyId($depart);
			$Company = new model_newagk_company();//实例化公司
			$CompanyName = $Company->getList(1);
			$CompanyName = self::setArrKeyId($CompanyName);
			$team = [];
			foreach($depart as $vc){
				if($v['pid']>0){
					$team[$v['id']] = $v['name'];
				}
			}
			$positions = ['1'=>['id'=>1,'name'=>'安置','pid'=>0],'2'=>['id'=>1,'name'=>'检修','pid'=>0],'3'=>['id'=>1,'name'=>'送变电','pid'=>0]];//职位
			if($down=='excels'){
				foreach($res as $v){
				$Borns = empty($v['idcard']) ? '' : $dataY-substr($v['idcard'],6,4);
				$datas[] = [
						'id'=>$v['id'],
						
						'truename'=>$v['truename'], //姓名
						'idcard'=>$v['idcard'],	//身份号
						'phone'=>$v['mobile'],	//手机号
						'sex'=>$v['sex']==1 ? '男' : '女',		//性别
						'ages'=>$Borns,		//年龄
						'company_name'=>$v['companyName'], //公司
						'departmentId'=>empty($depart[$v['departmentId']]) ? '' : $depart[$v['departmentId']], //部门
						'teams'=>empty($depart[$v['departmentgroupId']]) ? '' : $depart[$v['departmentgroupId']], //班组
						'position'=>$v['position'], //职位
						'specialtyId'=>empty($Specialty[$v['specialtyId']]) ? '' : $Specialty[$v['specialtyId']], //专业
							];
				}
			
			} else {
				foreach($res as $v){

				//$uid[] = $v['uid'];
				$Borns = empty($v['idcard']) ? '' : $dataY-substr($v['idcard'],6,4);//intval
				$datas[] = [
						'id'=>$v['id'],
						'basicid'=>$basic->filename['basicid'],
						'userid'=>$v['identity_id'],
						'uid'=>$v['gdlUserId'],
						'truename'=>$v['truename'], //姓名
						'idcard'=>$v['idcard'],	//身份号
						'phone'=>$v['mobile'],	//手机号
						'sex'=>$v['sex']==1 ? '男' : '女',		//性别
						'ages'=>$Borns,		//年龄
						'company_name'=>$v['companyName'], //公司
						'departmentId'=>empty($depart[$v['departmentId']]) ? '' : $depart[$v['departmentId']], //部门
						'teams'=>empty($depart[$v['departmentgroupId']]) ? '' : $depart[$v['departmentgroupId']], //班组
						'position'=>$v['position'], //职位
						'specialtyId'=>empty($Specialty[$v['specialtyId']]) ? '' : $Specialty[$v['specialtyId']], //专业
						'photo'=>empty($v['photoCollect']) ? 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1295886065,1357964878&fm=27&gp=0.jpg' : $v['photoCollect'], //留底
							];
				}
				
			}*/
			/*
			if(!empty($uid)){
				$ucenterUser = $ucentermember->getListByArg('id('.implode(',',$uid).')','id,truename,mobile,idcard');
				foreach($ucenterUser as $vuser){
					$Borns = empty($vuser['idcard']) ? '' : $dataY-substr($vuser['idcard'],7,8);
					$datas[$vuser['id']]['truename'] = $vuser['truename'];
					$datas[$vuser['id']]['idcard'] = $vuser['idcard'];
					$datas[$vuser['id']]['phone'] = $vuser['mobile'];
					$datas[$vuser['id']]['ages'] = $Borns;
				}
			}
			*/
		/*	if(empty($datas)){
				$result->code = 0;
			} else {
				$datac['Specialty'] = is_array($Specialty) ? $Specialty : [];
				$datac['depart'] = is_array($depart) ? $depart : [];
				$datac['company'] = is_array($Company) ? $Company : [];
				$datac['team'] = is_array($team) ? $team : [];
				$datac['positions'] = is_array($positions) ? $positions : [];
				$datac['num'] = $num['num'];
				$result->code = 1;
				$result->data = $datas;
				$result->message = json_encode($datac);
			}

            $result->success = true;
		} catch (Exception $e) {
            $result->success = false;
            $result->code = $e->getCode();
            $result->message = $e->getMessage();
        }
        return $result;
	}
	*/
	
	//用户移除考场
    public function basicUserDel(BasicuserRequestDTO $basic)
    {
		$result = new ResultDO();
		$datas = $basic->filename ? $basic->filename : [];
	
		
		
		try{
			$basicuser = new model_newagk_basicuser();
	
			$condition = ' basic_id='.$datas['basicid'].' and identity_id in('.$datas['identity_id'].')';

			/******查询条件********/
			/******查询条件 end********/
			$basicuser->delete($condition);
		
				$result->code = 1;
				 $result->message = '移除成功';
			

            $result->success = true;
		} catch (Exception $e) {
            $result->success = false;
            $result->code = $e->getCode();
            $result->message = $e->getMessage();
        }
        return $result;
	}
	
	
	//用户添加用户到考场
    public function basicUserAdd(BasicuserRequestDTO $basic)
    {
		$result = new ResultDO();
		$datas = $basic->filename ? $basic->filename : [];
	
		
		
		try{
			$basicuser = new model_newagk_basicuser();

			$basic = $basicuser->userAdd($datas['basicid'],$datas['identity_id']);

		
				$result->code = 1;
				 $result->message = json_encode($basic);
			

            $result->success = true;
		} catch (Exception $e) {
            $result->success = false;
            $result->code = $e->getCode();
            $result->message = $e->getMessage();
        }
        return $result;
	}

	
	//获取参考人员id
    public function userList(BasicuserRequestDTO $basic)
    {
		$result = new ResultDO();
		$basicid = $basic->filename['basicid'] ? $basic->filename['basicid'] : 0;

		
		
		try{
			$basicuser = new model_newagk_basicuser();
			$identity_id = $basicuser->basicuser($basicid);
			if(empty($identity_id)){
				$result->code = 0;
			} else {
				$result->code = 1;
				$result->data[] = $identity_id;
			}

            $result->success = true;
		} catch (Exception $e) {
            $result->success = false;
            $result->code = $e->getCode();
            $result->message = $e->getMessage();
        }
        return $result;
	}
	
	public function setArrKeyId($arr) {
		if (!isset($arr))
			return false;
		$arrs = [];
		foreach ($arr as $key => $value) {
			$arrs[$value['id']] = $value;
		}
		return $arrs;
	}
	
	
	//历史考场人员列表
    public function basicHis(BasicuserRequestDTO $basic)
    {
		$result = new ResultDO();
		$reg = $basic->filename['reg'] ? gdl_lib_BaseUtils::getStr($basic->filename['reg'],'string') : '';
		$basicid = $basic->filename['basicid'] ? gdl_lib_BaseUtils::getStr($basic->filename['basicid'],'int') : 0;
		$examid = $basic->filename['examid'] ? gdl_lib_BaseUtils::getStr($basic->filename['examid'],'int') : 0;
		$status = $basic->filename['status'] ? gdl_lib_BaseUtils::getStr($basic->filename['status'],'int') : 0;
		$pass = $basic->filename['pass'] ? gdl_lib_BaseUtils::getStr($basic->filename['pass'],'string') : '';//failed不合格 //meets 合格
		$startScore = $basic->filename['startScore'] ? sprintf("%.2f",$basic->filename['startScore']) : 0;
		$endScore = $basic->filename['endScore'] ? sprintf("%.2f",$basic->filename['endScore']) : 0;
		$pages = $basic->filename['page'] ? gdl_lib_BaseUtils::getStr($basic->filename['page'],'int') : 1;
		$pagesize = $basic->filename['pagesize'] ? gdl_lib_BaseUtils::getStr($basic->filename['pagesize'],'int') : 10;
		$page = ($pages-1) * $pagesize;
		
		if(empty($reg) || !$basicid){
			$result->code = 0;
			$result->message = '缺少参数';
            $result->success = true;
			return $result;
		}
		try{
			$examspapers= new model_newagk_examspapers();
			$basicuser= new model_newagk_basicuser();
			$basic= new model_newagk_basic();
			$condition = ' 1 ';// reg
			/****获取 考场用户id****/
			$basic_userid = $basicuser->basicuser($basicid); 
			/*****获取考场用户id end******/
	
			if($examid){
				$condition .= ' and '.$examspapers->tableName().'.basicid='.$examid;
			}
			
			if($status){
				$condition .= ' and '.$examspapers->tableName().'.status='.$status;
			}
			if($pass=='meets'){
				$condition .= ' and '.$examspapers->tableName().'.modified>='.$examspapers->tableName().'.passscore';
			} else if($pass=='failed'){
					$condition .= ' and '.$examspapers->tableName().'.modified<'.$examspapers->tableName().'.passscore';
			}
			
			if($startScore){
				$condition .= ' and '.$examspapers->tableName().'.modified>='.$startScore;
			}
			if($endScore){
					$condition .= ' and '.$examspapers->tableName().'.modified<='.$endScore;
			}
			
			
			$leftJoin = array(
				$basic->tableName().' as c' => $examspapers->tableName().'.basicid=c.id',
				$basicuser->tableName().' as b' => $examspapers->tableName().'.identity_id=b.identity_id',

			);
			$orderBy = '  group by '.$examspapers->tableName().'.id order by '.$examspapers->tableName().'.id desc  limit '.$page.','.$pagesize;
			
			/******查询条件********/
			/******查询条件 end********/
			$items = $examspapers->tableName().'.id,'.$examspapers->tableName().'.identity_id,'.$examspapers->tableName().'.status,'.$examspapers->tableName().'.modified,'.$examspapers->tableName().'.passscore,b.usertruename,b.idcard,b.phone,c.basic';
			$num = $examspapers->selectOne($condition, 'count(*) num');
			$res = $examspapers->select($condition, $items, $orderBy, '', $leftJoin)->items;
			$datas = [];
			
			
			$status=[1=>'正常',2=>'作弊',3=>'人脸识别异常','4'=>'缺考'];
			foreach($res as $v){
				$datas[] = [
							"id"=>$v["id"],
							"status"=>empty($status[$v["status"]]) ? '未知' : $status[$v["status"]],
							"score"=>$v["status"]==4 ? '--' : $v["modified"],
							"userId"=>$v["identity_id"],
							"truename"=>$v["usertruename"],
							"idcard"=>empty($v["idcard"]) ? '' : substr($v["idcard"],0,3).'*****'.substr($v["idcard"],-4,4),
							"phone"=>$v["phone"],
							"basicName"=>$v["basic"],
							"suffice"=>$v["modified"]>=$v["passscore"] ? 'meets' : 'failed', // failed不合格 meets 合格
							'oper'=> in_array($v["identity_id"],$basic_userid) ? '1' : '0',
							];
			}

			if(empty($datas)){
				$result->code = 0;
				$result->message = '没有考试数据';
			} else {
				
				$result->code = 1;
				$result->data = $datas;
				$result->message = $num['num'];
			}

            $result->success = true;
		} catch (Exception $e) {
            $result->success = false;
            $result->code = $e->getCode();
            $result->message = $e->getMessage();
        }
        return $result;
	}

}
